import Vue from 'vue'
import user from './modules/user'
import VueRouter from 'vue-router'

Vue.use(VueRouter);
const VueRouterPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

const VueRouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (to) {
  return VueRouterReplace.call(this, to).catch(err => err)
}

// 文章列表页
const article = () => import('@/components/Table/ArticleListTable');
// 排行榜
const leaderBoard = () => import('@/components/LeaderBoard/LeaderBoard');
// 详情页
const detailsPage = () => import('@/views/Details/Detail');
// 首页
const Home = () => import('@/views/Home/Home');
// 用户
const User = () => import('@/views/User/User');

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: 'ArticleListTable/:type',
        name: "Article",
        component: article
      },
      {
        path: 'ArticleListTable/search',
        name: "搜索",
        component: article
      },
      {
        path: 'LeaderBoard',
        name: '导航栏',
        component: leaderBoard
      },
      {
        path: 'Details/:id',
        name: 'Details',
        component: detailsPage
      } 
    ]
  },
  {
    path: '/User/:id',
    name: 'User',
    component: User
  }
]

const router = new VueRouter({
  // mode: 'history',
  routes,
  modules: {
    user
  }
})

export default router
